<template>
    <el-dialog title="追加投放" width="30%" :visible="dialogVisible" :append-to-body="true" :before-close="closeHandle">
        <div class="info">
            <span class="add-info">地标点:</span><span class="info-area" style="margin-left: 27px;">{{ subParam.local
                }}</span>
        </div>
        <div class="info id-box">
            <span class="add-id">单车编号:</span>
            <el-input style="width: 80%;margin-left: 15px;" v-model="subParam.bycicleId"
                placeholder="输入单车编号"></el-input>
        </div>
        <div class="info">
            <span class="add-type">单车类型:</span>
            <el-button-group style="margin-left: 15px;">
                <el-button type="primary" @click="subParam.power = false" plain>自行车</el-button>
                <el-button type="primary" @click="subParam.power = true" plain>助力车</el-button>
            </el-button-group>
        </div>
        <div class="info id-box" style="display: flex; justify-content: flex-start;">
            <span class="add-id">最大里程数:</span>
            <el-input style="width: 30%;margin-left: 15px;" v-model="subParam.bikeInfo.mileage"
                placeholder="输入最大里程数(KM)"></el-input>
            <span class="add-id" style="margin-left: 10px;">电量:</span>
            <el-input style="width: 30%;margin-left: 15px;" v-model="subParam.bikeInfo.power"
                placeholder="输入单车电量"></el-input>
        </div>
        <div class="info" style="display: flex; justify-content: center; ">
            <el-button style="width: 50%;" type="primary" @click="resub">投放</el-button>
        </div>
    </el-dialog>
</template>

<script>
import API from "@/utils/request";
export default {
    emits: ["calledClosing"],
    props: ["visible", "local", "lat", "lng", "cityCode"],
    data() {
        return {
            dialogVisible: false,
            subParam: {
                bycicleId: "",
                power: false,
                local: "",
                bikeInfo: {
                    power: "",
                    mileage: ""
                }
            }
        }
    },
    watch: {
        visible(newVal) {
            console.log("发生了变化");
            this.dialogVisible = newVal;
        },
        local(newVal) {
            this.subParam.local = newVal;
        }
    },
    methods: {
        closeHandle() {
            this.dialogVisible = false;
            this.$emit("calledClosing");
        },
        resub() {
            var req = {
                "bikeMode": this.subParam.power ? "1" : "2",
                "platform": '轻悠',
                "lat": this.lat,
                "lng": this.lng,
                "bikeId": this.subParam.bycicleId,
                "cityCode": this.cityCode,
                "mileage": this.subParam.bikeInfo.mileage,
                "power": this.subParam.bikeInfo.power,
                "parkName": this.subParam.local,
                "pic": ""
            };
            console.log(req);
            API.addBike(req, ((res) => {
                console.log(res);
                if (res.code === 200) {
                    this.$message({
                        message: '添加成功',
                        type: 'success'
                    });
                    this.$emit("calledClosing");
                }
                else {
                    this.$message({
                        message: res.data,
                        type: 'error'
                    });
                    this.$emit("calledClosing");
                }
            }))
            // this.$emit("calledReSub");
        }
    }

}
</script>

<style>
.info {
    line-height: 30px;
    margin-bottom: 20px;
}
</style>